package com.googlecode.droidcare.common;

import java.io.PrintStream;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.googlecode.droidcare.common.api.exception.ExceptionHandler;
import com.googlecode.droidcare.common.api.net.HttpService;
import com.googlecode.droidcare.common.provider.ProviderManager;
import com.googlecode.droidcare.common.usr.UserAccount;

@Singleton
@SuppressWarnings("rawtypes")
public final class AppContext {
	
	private ProviderManager providerManager;
	private ScriptEngine scriptEngine;
	private HttpService httpService;
	private UserAccount userAccount;
	private Injector injector;
	public PrintStream stream = System.out;
	
	@Inject
	protected static Provider<AppContext> contexProvider;
	
	@Inject
	protected static Provider<com.googlecode.droidcare.common.provider.Provider> mnoProvider;
	
	@Inject
	protected static Provider<ExceptionHandler> exceptionHandlerProvider;
	
	public ProviderManager getProviderManager() {
		return providerManager;
	}

	@Inject
	public void setProviderManager(ProviderManager providerManager) {
		this.providerManager = providerManager;
	}


	public ScriptEngine getScriptEngine() {
		return scriptEngine;
	}

	@Inject
	public void setScriptEngine(ScriptEngine scriptEngine) {
		this.scriptEngine = scriptEngine;
	}


	public HttpService getHttpService() {
		return httpService;
	}

	@Inject
	public void setHttpService(HttpService httpService) {
		this.httpService = httpService;
	}


	public UserAccount getUserAccount() {
		return userAccount;
	}

	@Inject
	public void setUserAccount(UserAccount userAccount) {
		this.userAccount = userAccount;
	}


	public Injector getInjector() {
		return injector;
	}

	@Inject
	public void setInjector(Injector injector) {
		this.injector = injector;
	}

	public com.googlecode.droidcare.common.provider.Provider newProvider() {
		return mnoProvider.get();
	}
	
	public static AppContext getInstance() {
		return contexProvider.get();
	}
	
	public static ExceptionHandler getExceptionHandler() {
		return exceptionHandlerProvider.get();
	}

}
